public class MatrixMultiplyThread extends Thread
{
    private double[][] matrix1;
    private double[][] matrix2;
    private double[][] result;
    private MatrixMultiply matrixMultiply;

    MatrixMultiplyThread(MatrixMultiply matrixMultiply, double[][] result)
    {
        this.matrix1 = matrixMultiply.getMatrix1();
        this.matrix2 = matrixMultiply.getMatrix2();
        this.result = result;
        this.matrixMultiply = matrixMultiply;
    }

    @Override
    public void run()
    {
        super.run();
        double count = 0.0;
        while (true)
        {
            int[] pos = matrixMultiply.next();
            if (pos == null)
                return;
            int row = pos[0];
            int column = pos[1];
            for (int k = 0; k < matrix1[0].length; k++)
            {
                count += matrix1[row][k] * matrix2[k][column];
            }
            result[row][column] = count;
            count = 0.0;
        }
    }
}
